<?php
$this->breadcrumbs = array(
    Shop::t('Products'),
);
Shop::renderFlash();
$currentPage = $pages->getCurrentPage()+1;
?>

<div class="sub-page">
    <h2>All products</h2>

    <div class="sort">
        Sort by:&nbsp;
        <select name="sort" id="goto">
            <option>-- Select --</option>
            <option <?php if($sort == 'stock DESC, price asc') echo 'selected';?> value='<?php echo $this->createUrl("/shop/products/all"). "/price/asc/page/$currentPage";?>'>Price: Low to High</option>
            <option <?php if($sort == 'stock DESC, price desc') echo 'selected';?> value='<?php echo $this->createUrl("/shop/products/all"). "/price/desc/page/$currentPage";?>'>Price: High to Low</option>
            <option <?php if($sort == 'stock DESC, created_time desc') echo 'selected';?> value='<?php echo $this->createUrl("/shop/products/all"). "/date/desc/page/$currentPage";?>'>Date: New to Old</option>
            <option <?php if($sort == 'stock DESC, created_time asc') echo 'selected';?> value='<?php echo $this->createUrl("/shop/products/all"). "/date/asc/page/$currentPage";?>'>Date: Old to New</option>
        </select>
    </div>
    <div class="paging-block">
        <p>Displaying <?php echo $pages->getCurrentPage()* $page_size +1;?>  to <?php echo ($item_count >= (($pages->getCurrentPage()+1) * $page_size))?($pages->getCurrentPage()+1) * $page_size : $item_count;?> (of <?php echo $item_count?> products)</p>

        <div class="pages">
            <?php
            // the pagination widget with some options to mess
            $this->widget('MyLinkPager', array(
                'currentPage' => $pages->getCurrentPage(),
                'itemCount' => $item_count,
                'pageSize' => $page_size,
                'maxButtonCount' => 5,
                'header' => '',
                'htmlOptions' => array('class' => 'pages'),
            ));
            ?>
        </div>
    </div>
    <div class="all-product">
        <?php foreach ($model as $key => $data) { 
            $data['price'] = intval(($data['price'])?$data['price'] + $data['frame']['price_adjustion']:$data['price']);
            $data['new_price'] = intval(($data['new_price'])?$data['new_price'] + $data['frame']['price_adjustion']:$data['new_price']);
        ?>
            <div class="prd-textt">
                <div class="prd-textt-pict">
                    <span class="large-pict"><a href="<?php echo $this->createUrl('/shop/products/view', array('id'=>$data['product_id']))?>">
                            <img src="<?php echo Yii::app()->request->baseUrl ?>/data/upload/products/<?php echo isset($data->shopImages[count($data->shopImages)-1]) ? $data->shopImages[count($data->shopImages)-1]->filename : 'no_image.jpg'?>"
                                width="260" height="260"></a></span>
                    <?php if ($data['stock']):?>
                        <span class="small-pict green-text">In Stock</span>
                    <?php else :?>
                        <span class="small-pict red-text">Out of Stock</span>
                    <?php endif;?>
                </div>
                <div class="prd-detail">
                    <p>Date Added: <?php echo date('l d F, Y', strtotime($data['created_time'])) ?></p>
                    <hr>
                    <h2><a href="<?php echo $this->createUrl('/shop/products/view', array('id'=>$data['product_id']))?>"><?php echo $data['title'] ?></a></h2>

                    <p class="label"><strong>Product Code:</strong> <?php echo $data['product_code'] ?></p>

                    <p class="label"><strong>Manufacturer:</strong> <?php echo $data['manufacturer'] ?> </p>

                    <p class="label"><strong>Weight:</strong> <?php echo $data['weight'] ?>gram</p>

                    <p class="label"><strong>Size:</strong> <?php echo $data['size'] ?>(cm)</p>
                    
                    <p class="marT20">
                        <span style="margin:7px 15px 0 0" class="floatL"><strong>Price:</strong></span>
                        <?php if ($data['price'] && $data['new_price']) { ?>
                            <span class="old-price">$<?php echo $data['price'] ?></span>
                            <span class="new-price">$<?php echo $data['new_price'] ?></span>
                        <?php } else { ?>
                            <span class="new-price">$<?php echo ($data['price'])?$data['price']:''; ?></span>
                        <?php } ?>
                    </p>

                    <div class="clearB"></div>
                    <?php if ($data['stock']):?>
                    	<a class="red-button marT20 buy-now" rel="<?php echo ($data['frame']['price_adjustion'])? $data['product_id'] .'-1':$data['product_id'] .'-0';?>" href="javascript:void(0)">Buy now</a>
                    <?php endif;?>
                </div>
                <p class="detail">
                    <strong style="color:#000000">Details:</strong><br/>
                    <?php 
                    $description = strip_tags($data['description']);
                    if(!empty($description)) :
                        $data['description'] = str_replace('&nbsp;', '', $data['description']);
                        $output = new CutStringHelper($data['description'], 350);
                        echo $output->cut(); 
                    ?>
                        <span><a href="<?php echo $this->createUrl('/shop/products/view', array('id'=>$data['product_id']))?>"><strong style="color:#000000">&NestedGreaterGreater; More info</strong></a></span>
                    <?php endif;?>
                </p>
            </div>
        <?php } ?>
    </div>
    <div class="paging-block">
        <p>Displaying <?php echo $pages->getCurrentPage()* $page_size +1;?>  to <?php echo ($item_count >= (($pages->getCurrentPage()+1) * $page_size))?($pages->getCurrentPage()+1) * $page_size : $item_count;?> (of <?php echo $item_count?> products)</p>

        <div class="pages">
            <?php
            // the pagination widget with some options to mess
            $this->widget('MyLinkPager', array(
                'currentPage' => $pages->getCurrentPage(),
                'itemCount' => $item_count,
                'pageSize' => $page_size,
                'maxButtonCount' => 5,
                'header' => '',
                'htmlOptions' => array('class' => 'pages'),
            ));
            ?>
        </div>
    </div>
</div>